<?php

class AdminModel extends Model{
	
	protected $trueTableName  = 'admin';
	
	public function get() {
		$result = $this->find();
		
		if(!empty($result)) {
			$result['authority'] = unserialize($result['authority']);
		}
		
		return $result;
	}
	
	public function getlist() {
		$result = $this->select();
		
		if(!empty($result)) {
			foreach($result as $k=>$v) {
				$result[$k]['authority'] = unserialize($v['authority']);
			}
		}
		
		return $result;
	}
	
	public function mysave($shuju) {
		$where = $this->options['where'];
		
		//取权限的下标组成数组
		$authority = authority();
		$ka = array();
		foreach($authority as $k=>$v) {
			$ka[] = $k;
		}
		
		//用户有效状态
		$data = array();
		if(isset($shuju['status']) && $shuju['status']==1) {
			$data['status'] = 1;
			unset($shuju['status']);
		}else{
			$data['status'] = 0;
		}
		
		
		//更新数据是否符合权限
		$temp = array();
		if(!empty($shuju)) {
			foreach($shuju as $k=>$v) {
				if(in_array($k,$ka)) {
					$temp[] = $k;
				}
			}
		}
		
		if(!empty($temp)) {
			$data['authority'] = serialize($temp);//将权限编辑成需要类型
		}else{
			$data['authority'] = "";//将权限编辑成需要类型
		}
		
		$this->where($where)->save($data);
	}
	
	

	
}

?>